package com.jffccloud.provider.service.impl;

import com.codingapi.txlcn.commons.annotation.TxTransaction;
import com.jffccloud.common.exception.BusinessException;
import com.jffccloud.common.web.wrapper.Wrapper;
import com.jffccloud.provider.api.mapper.DemoMapper;
import com.jffccloud.provider.api.model.Demo;
import com.jffccloud.provider.api.model.OrderDto;
import com.jffccloud.provider.api.service.OrderFeignApi;
import com.jffccloud.provider.service.IUserService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
public class UserServiceImpl implements IUserService {
    @Resource
    private OrderFeignApi orderFeignApi;
    @Resource
    private DemoMapper demoMapper;
    @Resource
    private DemoDisruptorService demoDisruptorService;
    @TxTransaction
    public OrderDto queryOrderByNo(String no){
        Demo demo = new Demo();
        demo.setName("2222");
        demoMapper.insert(demo);
        Wrapper<OrderDto> wrapper = orderFeignApi.queryByOrderNo(no);
        if (wrapper == null) {
            throw new BusinessException("订单不存在");
        }
        if (wrapper.error()) {
            throw new BusinessException(wrapper.getMessage());
        }
        demoDisruptorService.execute(demo);
       return wrapper.getResult();
    }
}
